import redis
from flask import request

REDIS_POOL = redis.ConnectionPool(host='redis-master', port=6379,
                                  max_connections=256, db=0)


def get_redis_conn():
    redis_conn = getattr(request, 'redis_conn', None)
    if not redis_conn:
        redis_conn = redis.Redis(connection_pool=REDIS_POOL)
        setattr(request, 'redis_conn', redis_conn)
    return redis_conn
